1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class EnemyController : MonoBehaviour {
6
7     
public float speed;
8
9     
private Rigidbody2D myRigidBody;
10
11     
void Awake(){
12         myRigidBody = GetComponent<Rigidbody2D> ();
13     }
14
15     
// Use this for initialization
16     
void Start () {
17         
18     }
19     
20     
// Update is called once per frame
21     
void Update () {
22         EnemyMovement ();
23     }
24
25     
void EnemyMovement(){
26         myRigidBody.velocity =
new Vector2 (myRigidBody.velocity.x, -speed);
27     }
28
29     
void OnTriggerEnter2D(Collider2D collider){
30         
if(collider.CompareTag("Player")){
31             collider.transform.GetComponent<PlayerController> ().PlayerDied ();
32         }
33     }
34 }


Use this for initialization

Update is called once per frame



Gõ tìm kiếm nhanh...